package com.sm.tools;

import java.util.ArrayList;

import com.sm.bo.Course;
import com.sm.bo.Student;

public class StudentsManager {
	
	public static int addStudent(ArrayList<Student> studentsList, Student student){
		studentsList.add(student);
		return 1;
	}
	
	public static int removeStudent(ArrayList<Student> studentsList, String name){
		Student studentR = getStudentByName(studentsList, name);
		if (studentR != null) {
			studentsList.remove(studentR);
			return 1;
		} else {
			return 0;
		}
	}
	
	private static Student getStudentByName(ArrayList<Student> studentsList, String name){
		Student studentR = null;
		for (Student student :  studentsList) {
			if (studentR.getName().equals(name))
				studentR = student;
		}
		return studentR;
	}
	
	public static int addCourseToStudent(Student student, String courseCode)
	{
		if (!student.getCourses().contains(courseCode)) {
			student.getCourses().add(courseCode);
		}
		return 1;
	}
}
